{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e80154c2",
   "metadata": {},
   "source": [
    "-------------------\n",
    "* 本周主要内容：图像识别（人脸识别）\n",
    "* 记录人：严纬琦\n",
    "* 日期：2023年3月24日 周五\n",
    "-------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3255730",
   "metadata": {},
   "source": [
    "## 上周内容\n",
    ">1. API文档阅读(考试) \n",
    ">2. requests模块(考试)\n",
    ">3. 百度通用图像识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5445ed3c",
   "metadata": {},
   "source": [
    "# 本周内容：Face++实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8a1eaf9f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "400\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('C:/Users/28563/yyqx.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2.酬载准备\n",
    "payload = {\n",
    "    'api_key':'WNkcSZh3sIXgVVELiJt4jXcTXpdq_bE_',\n",
    "    'api_secret':'gSRqPE6IgUQ_wyYPouxv8uovbJhMKiJr',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,mouthstatus,eyegaze,skinstatus'}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dac8953c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用文字识别（高精度版）\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('yyqx.jpg','rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"api_key\":\"WNkcSZh3sIXgVVELiJt4jXcTXpdq_bE_\",\n",
    "    \"api_secret\":\"gSRqPE6IgUQ_wyYPouxv8uovbJhMKiJr\",\n",
    "    \"image_base64\":img,   \n",
    "    \"return_attributes\":\"gender,age,emotion,beauty\"\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "print(response.status_code)\n",
    "print (response.json())\n",
    "\n",
    "    \n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
